﻿var Cache={
	datacache:{}   //缓存
};
var Default={
	link:"default.html"
}
var NotFound={
	link:'notfound.html'
}

var remain = {
	id:0,
	link:'operator.html'
}
var Standard_List={
	link:'Standard_List.html',
	id:1
}
var wareshouse = {
	id:2,
	link:'warehouse.html'
}
var Waybill_List={
	link:'Waybill_List.html',
	id:3
}
var Report_List={
	link:'Report_List.html',
	id:4
}
var Business_List={
	link:'Business_List.html',
	id:5
}
var Standard_List_wm={
	link:'Standard_List_wm.html',
	id:6
}

var Waybill_List_wm={
	link:'Waybill_List_wm.html',
	id:7
}

var page4={
	link:'page4.html',
	id:9
}

var page6={
	link:'page6.html',
	id:7
}
var bill_detail={
    link:'bill_detail.html',
    id:8
}
var Ymagic = {

	init:function(){
		timelist=null;
	  var that= this;
	  if($.cookie('account')){
	  	var account=$.cookie('account');
	  	$('.login-wrap').hide();
	  	$('.logined-wrap').html('<a href="" class="username">'+account+'</a>|<a href="javascript:;" class="loginout">退出</a>').show();

	  	$('.loginout').on('click',function(){
	  		 $.ajax({
                    url: COMMONURL+'api/Account/LoginOut?token='+$.cookie('token')+'&account='+$.cookie('account'),
                    type: 'post',
                    dataType: 'json'
                }).done(function(data) {
                    if(data.recode=='0000'){
                    	$.removeCookie('token',{ path:'/',domain:'7yunbao.com' });
						$.removeCookie('usertype',{ path:'/',domain:'7yunbao.com' });
						$.removeCookie('account',{ path:'/',domain:'7yunbao.com' });
                    	window.location.href='http://www.7yunbao.com/';
                    }else{
                    	alert('登出失败!');
                    	$.removeCookie('token',{ path:'/',domain:'7yunbao.com' });
						$.removeCookie('usertype',{ path:'/',domain:'7yunbao.com' });
						$.removeCookie('account',{ path:'/',domain:'7yunbao.com' });
                    	//window.location.href='http://www.7yunbao.com/';
                    }
                });
	  	})
	  }
	  else
	  {
	      window.location.href = 'http://www.7yunbao.com/';
	  }
	  that.didMount();
      that.initBillDetail();
	},

	didMount:function(){
        if(timelist!=null){
        	clearInterval(timelist)
        }
		var that = this;
		var url = location.hash.replace('#','').split("&")[0];
		
		url=(""==url)?'Default':(!window[url]?'NotFound':url);
		var index=window[url].id;

		// if(index!=undefined){

		// 	$(".left-list").find("li").removeClass("current").eq(index).addClass("current");
		// }else{
		// 	$(".left-list").find("li").removeClass("current")
		// }
		if(Cache.datacache[url]){
			$("#rightWrap").html(Cache.datacache[url]);
			that.render(url)
		}else{
		 $.ajax({url:window[url].link}).done(function(data){
			Cache.datacache[url]=data;
	  	  $("#rightWrap").html(data);
	  	  that.render(url)
	    })
		}
	},

    // xjc add
    initBillDetail: function(){
        var url = 'bill_detail';
        if(Cache.datacache[url]){
            $("body").append(Cache.datacache[url]);
        }else{
            $.ajax({url:window[url].link}).done(function(data){
                Cache.datacache[url]=data;
                $("body").append(data);
            })
        }
    },

	render:function(url){
	   var callback = window[url].render;
		if(typeof callback === 'function') {
        callback();

     
    }

	}
}


Ymagic.init();  //初始化